

import org.junit.Test
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.By
import org.junit.After
import org.openqa.selenium.WebDriver
import org.openqa.selenium.interactions.Actions

class DragAndDrop {

    WebDriver driver = new FirefoxDriver()


    @Test
    void shouldShowTheCorrectTextWhenDraggingAndDroppingTheGreenColour()
    {
        driver.navigate().to("http://zacc.github.com/ldnse7/ldnse7_drag_drop.html#")
        def allSourceElements = driver.findElements(By.className("draggable"))
        def allTargetElements = driver.findElement(By.className("droppable"))



        allSourceElements.each { sourceElement ->
            def sourceElementColor = sourceElement.getCssValue("border-color").substring(4,14)

            allTargetElements.each { targetElement ->
                def targetElementColor = targetElement.getCssValue("background-color").substring(4,14)
                if (sourceElementColor == targetElementColor)
                {
                    print "found match with " + sourceElementColor
                    def actionsToPerform = new Actions()
                    actionsToPerform.clickAndHold(sourceElement)
                    actionsToPerform.moveToElement(targetElement)

                }
            }
        }



    }

    @After
    def void killBrowser()
    {
        driver.quit()
    }
}
